package com.ruoyi.test.web;

import com.ruoyi.test.domain.Channel;
import com.ruoyi.test.domain.common.Result;
import com.ruoyi.test.dto.JoinChannelDto;
import com.ruoyi.test.serv.IChannelServ;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hello/channel")
public class ChannelController {
    @Autowired
    private IChannelServ channelServ;

    @GetMapping("/getAllChannel")
    public Result<List<Channel>> getAllChannel() {
        return channelServ.getAllChannel();
    }

    @PostMapping("/add")
    public Result add(@RequestBody Channel channel) {
        return channelServ.add(channel);
    }

    @GetMapping("/getAllUserByChannelName")
    public Result<List<String>> getAllUserByChannelName(@RequestParam("channelName") String channelName) {
        return channelServ.getAllUserByChannelName(channelName);
    }

    @PostMapping("/joinChannel")
    public Result add(@RequestBody JoinChannelDto joinChannelDto) {
        return channelServ.joinChannel(joinChannelDto);
    }

    @PostMapping("/exitChannel")
    public Result exitChannel(@RequestBody JoinChannelDto joinChannelDto) {
        return channelServ.exitChannel(joinChannelDto);
    }

    @PostMapping("/removeChannel")
    public Result removeChannel(@RequestBody String channelName) {
        return channelServ.removeChannel(channelName);
    }
}
